package com.ruoyi.common.utils.security;

import cn.hutool.core.text.UnicodeUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.ruoyi.common.utils.StringUtils;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;

public class Test {

    public static void main(String[] args) {
        String token = testLogin();
        /*testLiveList(token);
        testLiveInfo(token);
        testLiveNews(token);
        testLiveCate(token);*/
        testLiveRanking(token);
    }

    public static String testLogin() {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("devices_uuid", "8CAC19EB-D87F-40D3-BF35-66DC30D01D35");
        paramMap.put("type", "ios");
        String result = HttpUtil.post("https://eksaweb.xyz:8888/api/v1/login", paramMap);
        String token = "";
        try {
            result = AesUtil.decrypt(new String(result.getBytes(), "UTF-8"), "AbpDspjkVNnnXVwg", "tSKANBW7rhGW5hN3");
            result = UnicodeUtil.toString(result);
            JSONObject jsonObject = JSONUtil.parseObj(result);
            String code = jsonObject.getStr("code");
            if ("200".equals(code)) {
                JSONObject dataJson = jsonObject.getJSONObject("data");
                if (StringUtils.isNotNull(dataJson)) {
                    token = dataJson.getStr("token");
                }
            }
            System.out.println("调用第三方登录接口获取的token值: " + token);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return token;
    }

    public static void testLiveList(String token) {
        // String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJpc3MiLCJhdWQiOiJhdWQiLCJqdGkiOiIwZTg4ZjJhZDNiYzc5OTYwMzQ2ZTA0ZTNjMTU4MDE4OCIsImlhdCI6MTYxNDc0NTg1NSwibmJmIjoxNjE0NzQ1ODU1LCJleHAiOjE2MTU5NTU0NTUsInVpZCI6MTE0MTUyMjB9.Qs_HDjFIw5Iov7eQ4Q0mswyzM0D6V5a0Vw6LGgqZPHQ";
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", 1);
        paramMap.put("limit", 10);
        // paramMap.put("token", token);
        String result = HttpUtil.post("https://eksaweb.xyz:8888/api/v1/live", paramMap);
        try {
            result = AesUtil.decrypt(new String(result.getBytes(), "UTF-8"), "AbpDspjkVNnnXVwg", "tSKANBW7rhGW5hN3");
            result = UnicodeUtil.toString(result);
            System.out.println("直播列表接口: " + result);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    public static void testLiveInfo(String token) {
        // String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJpc3MiLCJhdWQiOiJhdWQiLCJqdGkiOiIwZTg4ZjJhZDNiYzc5OTYwMzQ2ZTA0ZTNjMTU4MDE4OCIsImlhdCI6MTYxNDc0NTg1NSwibmJmIjoxNjE0NzQ1ODU1LCJleHAiOjE2MTU5NTU0NTUsInVpZCI6MTE0MTUyMjB9.Qs_HDjFIw5Iov7eQ4Q0mswyzM0D6V5a0Vw6LGgqZPHQ";
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("name", "jsonfanjiashequ.txt");
        // paramMap.put("token", token);
        String result = HttpUtil.post("https://eksaweb.xyz:8888/api/v1/live_anchor", paramMap);
        try {
            result = AesUtil.decrypt(new String(result.getBytes(), "UTF-8"), "AbpDspjkVNnnXVwg", "tSKANBW7rhGW5hN3");
            result = UnicodeUtil.toString(result);
            System.out.println("直播详情接口: " + result);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    public static void testLiveNews(String token) {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", 1);
        paramMap.put("limit", 10);
        String result = HttpUtil.post("https://eksaweb.xyz:8888/api/v1/news", paramMap);
        try {
            result = AesUtil.decrypt(new String(result.getBytes(), "UTF-8"), "AbpDspjkVNnnXVwg", "tSKANBW7rhGW5hN3");
            result = UnicodeUtil.toString(result);
            System.out.println("视频最新接口: " + result);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    public static void testLiveCate(String token) {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("category_id", "2");
        String result = HttpUtil.post("https://eksaweb.xyz:8888/api/v1/cate", paramMap);
        try {
            result = AesUtil.decrypt(new String(result.getBytes(), "UTF-8"), "AbpDspjkVNnnXVwg", "tSKANBW7rhGW5hN3");
            result = UnicodeUtil.toString(result);
            System.out.println("视频分类接口: " + result);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    public static void testLiveRanking(String token) {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", 1);
        paramMap.put("limit", 10);
        String result = HttpUtil.post("https://eksaweb.xyz:8888/api/v1/ranking", paramMap);
        try {
            result = AesUtil.decrypt(new String(result.getBytes(), "UTF-8"), "AbpDspjkVNnnXVwg", "tSKANBW7rhGW5hN3");
            result = UnicodeUtil.toString(result);
            System.out.println("视频排名接口: " + result);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

}
